cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(EmbeddedPythonExample  VERSION 1.0.0 LANGUAGES C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_STANDARD_REQUIRED ON)

find_package(PythonInterp  REQUIRED)

if(PYTHONINTERP_FOUND)
    message(STATUS "Found Python interpreter: ${PYTHON_EXECUTABLE} (version ${PYTHON_VERSION_STRING})")
endif()

find_package(PythonLibs ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} EXACT REQUIRED)

# 打印找到的 Python 库信息，方便调试
if(PYTHONLIBS_FOUND)
    message(STATUS "Found Python development libraries: ${PYTHON_LIBRARIES}")
    message(STATUS "Found Python include directories: ${PYTHON_INCLUDE_DIRS}")
else()
    # 如果找不到 Python 开发组件，由于使用了 REQUIRED，这里通常不会被执行，但可以作为备用处理
    message(FATAL_ERROR "Could not find required Python development libraries (headers and libs).")
endif()


# 添加一个可执行目标，使用我们的 C 源文件
add_executable(helloPython helloPython.c)

# 为可执行目标添加 Python 头文件所在的目录
target_include_directories(helloPython
  PRIVATE
      ${PYTHON_INCLUDE_DIRS}
)

# 将 Python 库链接到可执行目标
target_link_libraries(helloPython
  PRIVATE
      ${PYTHON_LIBRARIES}
)